let RouteModel = require('../model/ControllerModel')
const { userAPI } = require('../configure')

class School extends RouteModel {

  constructor () {super()}

  // 开通学校
  async create (ctx, next) {
    let data = ctx.request.fields;
    let result = await this.request({
      method: "POST",
      url: `${userAPI}/biz/school`,
      body: {"data": data}
    }, ctx.query.traceId);
    result && ctx.$success(result)
  }

  // 更新学校
  async update (ctx, next) {
    let data = ctx.request.fields,
        schoolId = ctx.params.school;
    let result = await this.request({
      method: "POST",
      url: `${userAPI}/biz/school/${schoolId}`,
      body: {"data": data}
    }, ctx.query.traceId);
    result && ctx.$success(result)
  }

  // 查询全量因素列表
  async index (ctx, next) {
    let data = ctx.query;
    let result = await this.request({
      method: "POST",
      url: `${userAPI}/biz/getSchool`,
      body: data
    }, ctx.query.traceId);
    result && ctx.$success(result)
  }

  // 学校详细信息
  async show (ctx, next) {
    let params = ctx.params;
    let result = await this.request({
      url: `${userAPI}/biz/school/${params.school}`
    }, ctx.query.traceId);
    result && ctx.$success(result)
  }

  // 修改状态
  async edit (ctx, next) {
    let { status } = ctx.query,
        { school } = ctx.params;
    let result = await this.request({
      url: `${userAPI}/biz/school/${school}/${status}`,
      method: 'POST'
    })
    result && ctx.$success(result)
  }

  // 校验学校名称
  async isExist (ctx, next) {
    let query = ctx.query;
    let result = await this.request({
      url: `${userAPI}/biz/school/isExist`,
      method: 'POST',
      body: {
        data: {
          cname: query.name
        }
      }
    })
    result && ctx.$success(result)
  }

}

module.exports = School
